/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tenorserver;

import Settings.BaseSettings;
import Settings.ISettings;
import static com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type.Element;
import java.io.File;
import java.net.InetAddress;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

/**
 *
 * @author Tomasz Nowak
 */
public class ServiceListenerSettings extends BaseSettings implements ISettings
{
	@Element
	InetAddress listeningAddress;

	@Element
	int listeningPort;

	@Element
	int verificationChallengeSize;

	public int getVerificationChallengeSize()
	{
		return verificationChallengeSize;
	}

	public void setVerificationChallengeSize( int verificationChallengeSize )
	{
		this.verificationChallengeSize = verificationChallengeSize;
	}

	public InetAddress getListeningAddress()
	{
		return listeningAddress;
	}

	public void setListeningAddress( InetAddress listeningAddress )
	{
		this.listeningAddress = listeningAddress;
	}

	public int getListeningPort()
	{
		return listeningPort;
	}

	public void setListeningPort( int listeningPort )
	{
		this.listeningPort = listeningPort;
	}

	@Override
	public void load()
	{
		try
		{
			Serializer serializer = new Persister();
			File source = new File(this.filename);
			ServiceListenerSettings settings = serializer.read(ServiceListenerSettings.class, source);

			this.listeningAddress = settings.listeningAddress;
			this.listeningPort = settings.listeningPort;
			this.verificationChallengeSize = settings.verificationChallengeSize;
		}
		catch ( Exception e )
		{
			e.printStackTrace();
		}
	}

	@Override
	public void save()
	{
		try
		{
			Serializer serializer = new Persister();
			File destination = new File(this.filename);
			serializer.write(this, destination);
		}
		catch ( Exception e )
		{
			e.printStackTrace();
		}
	}
}
